package TokenRecognizer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */
public class Thombson {
    private String sigma = "";
    public Thombson(){
        
    }
    
    public Automata basic(Transition t){
        Automata tautomata = new Automata();
        State b = new State();
        State e = new State();
        tautomata.addFirstState(b);
        tautomata.addLastState(e);
        tautomata.setTransition(b, b, new Transition('e'));
        tautomata.setTransition(e, e, new Transition('e'));
        tautomata.setTransition(b, e, t);
        if (!sigma.contains(t.toString()))
            sigma = sigma + t.toString();
        return tautomata;
    }

    public Automata concat(Automata a1, Automata a2){
        Automata tautomata = new Automata();
        tautomata.join(a1);
        tautomata.merge(a2);
        return tautomata;
    }

    public Automata or(Automata a1, Automata a2){
        Automata tautomata = new Automata();
        tautomata.join(a1);
        tautomata.join(a2);
        State b = new State();
        State e = new State();
        tautomata.addFirstState(b);
        tautomata.addLastState(e);
        tautomata.setTransition(b, a1.getFirstState(), new Transition('e'));
        tautomata.setTransition(b, a2.getFirstState(), new Transition('e'));
        tautomata.setTransition(a1.getLastState(), e, new Transition('e'));
        tautomata.setTransition(a2.getLastState(), e, new Transition('e'));
        tautomata.setTransition(b, b, new Transition('e'));
        tautomata.setTransition(e, e, new Transition('e'));
        return tautomata;
    }

    public Automata kleen(Automata a1){
        Automata tautomata = new Automata();
        tautomata.join(a1);
        State b = new State();
        State e = new State();
        tautomata.addFirstState(b);
        tautomata.addLastState(e);
        tautomata.setTransition(b, a1.getFirstState(), new Transition('e'));
        tautomata.setTransition(b, e, new Transition('e'));
        tautomata.setTransition(a1.getLastState(), a1.getFirstState(), new Transition('e'));
        tautomata.setTransition(a1.getLastState(), e, new Transition('e'));
        tautomata.setTransition(b, b, new Transition('e'));
        tautomata.setTransition(e, e, new Transition('e'));
        return tautomata;
    }

    public String getSigma(){
        return sigma;
    }
}
